package com.gaojinqi.sys.modular.rbac.model;

import com.gaojinqi.base.common.model.BaseTreeEntity;
import com.gaojinqi.base.core.jpa.annotation.Equals;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;

import static com.gaojinqi.sys.modular.rbac.model.Permission.TABLE_NAME;


/**
 * @author gaojinqi
 * @version 1.0
 * @since 2020年04月20日
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Entity
@Table(name = TABLE_NAME)
@org.hibernate.annotations.Table(appliesTo = TABLE_NAME, comment = "系统角色表")
public class Permission extends BaseTreeEntity<String> {

    public static final String TABLE_NAME = "sys_permission";

    public static final String PATH_SPLITTER = "==";
    public static final String SORT_FIELD = "sort";

    @Id
    @GeneratedValue(generator = TABLE_NAME + "_uuid")
    @GenericGenerator(name = TABLE_NAME + "_uuid", strategy = "uuid")
    @Column(columnDefinition = "varchar(32)  COMMENT '权限ID'")
    private String permissionId;

    @Column(columnDefinition = "varchar(32)  COMMENT '权限编码'", unique = true)
    @Equals
    private String permission;

    @Column(columnDefinition = "varchar(32)  COMMENT '权限名称'")
    private String permissionName;

    @Column(columnDefinition = "varchar(128)  COMMENT '请求路径'")
    private String url;

    @Column(columnDefinition = "varchar(16) COMMENT '请求方法'")
    private String method;

    // 0 是菜单类型
    @Column(columnDefinition = "int(2) default 0 COMMENT '类型'")
    private Byte type;

    @Column(columnDefinition = "int(4) default 0 COMMENT '启用状态'")
    private Byte state;

    @Column(columnDefinition = "varchar(16)  COMMENT '图标'")
    private String icon;

    @Column(columnDefinition = "varchar(128)  COMMENT '描述'")
    private String remark;

    @Column(columnDefinition = "int(16) COMMENT '排序'")
    private Integer sort;

    @Override
    public String getId() {
        return permissionId;
    }

    @Override
    public void setId(String id) {
        this.permissionId = id;
    }

}
